package binary_tree.sort.LeetCode;

import java.util.HashMap;
import java.util.Map;

public class Num205 {
    public boolean isIsomorphic(String s, String t) {
        Map<Character, Character> map1 = new HashMap<>();
        Map<Character, Character> map2 = new HashMap<>();
        //将s，t的字符串转化为数组存储在map集合中，key存储他们的元素值，value存储他们出现的次数
        for (int i = 0; i < s.length(); i++) {
            char a = s.charAt(i);
            char b = t.charAt(i);
            if ((map1.containsKey(a) && map1.get(a) != b) || (map2.containsKey(b) && map2.get(b) != a)) {
                return false;
            }
             map1.put(a,b);
            map2.put(b,a);
        }
        return true;
    }
}
